package com.ch02.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * @ClassName LoginServlet
 * @Description TODO
 * @Author Kx
 * @Date 2025/9/18 15:15
 * @Version 1.0
 */
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    /**
     * @author: kx
     * @date: 2025/9/18 15:15
     * @param req : 请求对象
     * @param resp : 响应对象
     * @description: 登录处理
    */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取用户登录信息
        String user = req.getParameter("user");
        // 将用户信息存储到 session 中
        req.getSession().setAttribute("user", user);
        req.getRequestDispatcher("/WEB-INF/chat.html").forward(req, resp);
    }
}
